package cn.mall.auth.service.impl;

import cn.mall.auth.domain.Role;
import cn.mall.auth.dto.RoleMenuDTO;
import cn.mall.auth.dto.RolePermissionDTO;
import cn.mall.auth.mapper.RoleMapper;
import cn.mall.auth.service.IRoleService;
import cn.mall.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Jarvis-Smith
 * @since 2023-11-30
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public List<String> loadPermissionSnsByRoleId(Long roleId) {
        return roleMapper.loadPermissionSnsByRoleId(roleId);
    }

    @Override
    public void saveRolePermission(RolePermissionDTO dto) {
        roleMapper.deleteRolePermissionByRoleId(dto.getRoleId());
        roleMapper.saveRolePermission(dto.getRoleId(),dto.getPermissionSns());
    }

    @Override
    public void saveRoleMenu(RoleMenuDTO dto) {
        roleMapper.deleteRoleMenuByRoleId(dto.getRoleId());
        roleMapper.saveRoleMenu(dto.getRoleId(),dto.getMenuId());
    }

    @Override
    public List<Long> loadMenuIdByRoleId(Long roleId) {
        return roleMapper.loadMenuIdByRoleId(roleId);
    }

    @Override
    public List<Long> loadRoleIds() {
        return roleMapper.loadRoleIds();
    }
}
